package cn.dlc.com.order.controller;

import cn.dlc.com.order.entity.Product;
import cn.dlc.com.order.feign.ProductService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author 邓立川
 * @date 2020/12/31 17:40
 * @desc 添加当前类的描述信息
 */
@RestController
@RequestMapping("order")
@Slf4j
public class OrderController {

    @Autowired
    private ProductService productService;

    @GetMapping("{id}")
    @SentinelResource(value = "findById",
            fallback = "orderFallBack",
            fallbackClass = FallBackClass.class,
            blockHandler = "orderBlockHandler",
            blockHandlerClass = BlockHandlerClass.class)
    public Product findById(@PathVariable("id") String id) {
        // 替换为服务名product-server
        Product product = productService.findById(id);
//        Product product = new Product();
        return product;
    }

}
